package com.jk.controller;

import com.jk.bean.Page;
import com.jk.bean.SendPage;
import com.jk.bean.TuTu;
import com.jk.service.GZService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("gz")
public class GZController {

    @Resource
    private GZService  gzService;

    @ResponseBody
    @RequestMapping("queryGZdu")
    public SendPage queryGZdu(Page  page,String  userid){
        return gzService.queryGZdu(page,userid);
    }

    @ResponseBody
    @RequestMapping("queryLunBoTu")
    public List<TuTu>  queryLunBoTu(){
        return  gzService.queryLunBoTu();
    }

    @ResponseBody
    @RequestMapping("queryBaoXiao")
    public List<TuTu> queryBaoXiao(){
        return  gzService.queryBaoXiao();
    }

    @ResponseBody
    @RequestMapping("queryShenDuYueDu")
    public  List<TuTu>  queryShenDuYueDu(){
        return  gzService.queryShenDuYueDu();
    }

    @ResponseBody
    @RequestMapping("tuiJian")
    public String tuiJian(TuTu  tu,String  username){
        gzService.tuiJian(tu,username);
        return  "";
    }

    @ResponseBody
    @RequestMapping("boWenPaiHang")
    public List<TuTu> boWenPaiHang(){
        return  gzService.boWenPaiHang();
    }


    @ResponseBody
    @RequestMapping("queryNamePaiXu")
    public SendPage queryNamePaiXu(Page  page){
        return  gzService.queryNamePaiXu(page);
    }

    @ResponseBody
    @RequestMapping("updateGZ")
    public  String  updateGZ(String  aid,String  sta){
        return gzService.updateGZ(aid,sta);
    }

    @ResponseBody
    @RequestMapping("queryUpDown")
    public  SendPage  queryUpDown(Page  page){
        return  gzService.queryUpDown(page);
    }


    @ResponseBody
    @RequestMapping("upDownAuthor")
    public  String  upDownAuthor(String aid,Integer  sta,Integer  num){
        gzService.upDownAuthor(aid,sta,num);
        return  "";
    }

     int aa=-1;

    @ResponseBody
    @RequestMapping("zhiDing")
    public String  zhiDing(Integer aid, Integer  sta, Integer  val, HttpSession session){
        if(sta==1){ //置顶
            session.setAttribute("zd"+aid,val);
            gzService.zhiDing(aid,aa);

        }

        if(sta==0){  //取消置顶
            Integer attribute = (Integer) session.getAttribute("zd" + aid);
            gzService.zhiDing(aid,attribute);
        }
        return  "";
    }
}
